<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <link href="css/mui.min.css" rel="stylesheet"/>
    <link href="css/font-awesome.min.css" rel="stylesheet" />
    <link href="css/app.css" rel="stylesheet"/>
    <script src="js/mui.min.js"></script>
    
    <style>
	    .mui-bar-nav ~ .mui-content {
	        padding-top: 44px;
		}
		.mui-bar-footer ~ .mui-content {
		    padding-bottom: 44px;
		}
		.mui-bar-tab ~ .mui-content {
		    padding-bottom: 50px;
		}
    </style>
    <script src="js/jquery-1.12.4.min.js"></script>
    <script src="js/app.js"></script>
    
</head>
<body>
	<header id="header" class="mui-bar mui-bar-nav app-main-background-color">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 id="headername" class="mui-title">案件</h1>
	    <a class="mui-icon mui-pull-right font-color-white" id="msg_btn"> <i class="fa fa-bell-o icon-animated-bell"  aria-hidden="true"></i></a>
	</header>
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item mui-active" href="html/case/list.html">
	        <span class="mui-icon mui-icon-chatboxes"></span>
	        <span class="mui-tab-label">案件</span>
	    </a>
	 
	    <a class="mui-tab-item" href="html/contacts.html">
	        <span class="mui-icon mui-icon-chatboxes"></span>
	        <span class="mui-tab-label">通讯录</span>
	    </a>
	    
	    
	    <a class="mui-tab-item" href="html/setting.html"> 
	        <span class="mui-icon mui-icon-gear"></span>
	        <span class="mui-tab-label">设置</span>
	    </a>
	</nav>
	
	
	<script type="text/javascript" charset="utf-8">
      	mui.init({statusBarBackground: '#F15A24'});
      	//设置默认打开首页显示的子页序号；
		var Index=0;
		//把子页的路径写在数组里面
		var subpages = ['html/case/list.html','html/contacts.html','html/setting.html'];
		
		
			
		
		//所有的plus-*方法写在mui.plusReady中或者后面。
		mui.plusReady(function() {
			plus.navigator.setStatusBarBackground( "#F15A24" );
			plus.screen.lockOrientation("portrait-primary");
			
		    initTabView();
		   
				   
            bindTapBar();
            
           
            
             plus.runtime.getProperty(plus.runtime.appid,function(inf){
		        var version = inf.version;
		        console.log("当前应用版本："+version);
		        app.checkUpdate(version,true);
		    });
           
            
    		var backButtonPress = 0;
			mui.back = function(event) {
				backButtonPress++;
				if (backButtonPress > 1) { 
					plus.runtime.quit();
				} else {
					plus.nativeUI.toast('再按一次退出应用');
				}
				setTimeout(function() {
					backButtonPress = 0;
				}, 1000); 
				return false;
			};
			
			

		});
		 
		
		function initTabView(){
			 var self = plus.webview.currentWebview();
			for (var i = 0; i < 3; i++) {
		        //创建webview子页
		        var sub = plus.webview.create( 
		            subpages[i], //子页url
		            subpages[i], //子页id
		            {
		                top: '45px',//设置距离顶部的距离
		                bottom: '50px'//设置距离底部的距离
		            }
		        );
		        //如不是我们设置的默认的子页则隐藏，否则添加到窗口中
		        if (i != Index) {
		            sub.hide(); 
		        }
		    //将webview对象填充到窗口
		        self.append(sub);
		    }
		}
		
		
		function bindTapBar(){
			 var activeTab = subpages[Index];
		    var title=document.querySelector(".mui-title");
	        //选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
			    //获取目标子页的id
			    var targetTab = this.getAttribute('href');
			    if (targetTab == activeTab) {
			        return;
			    } 
			    //更换标题
			    title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;  
			    //显示目标选项卡
			    plus.webview.show(targetTab);
			    //隐藏当前选项卡
			    plus.webview.hide(activeTab);
			    //更改当前活跃的选项卡
			    activeTab = targetTab;
			});
			$("#msg_btn").on('tap',function(e){
				mui.openWindow({
								url:"/html/case/chat_list.html",
								id:"/html/case/chat_list.html",
								createNew:true,
								show: {
									aniShow: 'pop-in'
								},
								waiting: {
									autoShow: false
								},
								extras:{
										
			    				},


					});
			});
		}
		
		window.addEventListener('newsId',function(event){
		  //获得事件参数
		  var title=document.querySelector(".mui-title");
		  title.innerHTML("列表页面");
		});
		function getAuditPush(){
				
					app.getAuditPush(function(data){
						console.log(JSON.stringify(data));
						var auditInfo = data.result_data;
						var case_code = auditInfo.CASE_CODE;
						var audit_flag = auditInfo.AUDIT_FLAG;
						if(audit_flag == '1'){
							plus.nativeUI.toast('您案件号为:' +case_code +'已审核通过');
						}
						else if(audit_flag == '2'){
							plus.nativeUI.toast('您案件号为:' +case_code +'未审核通过,请关注');
						}
						var listPage = plus.webview.getWebviewById('html/case/list.html');
						if(listPage){
							 mui.fire(listPage,'refreshList');
							 plus.device.vibrate( 2000 );
						}
					},function(){
						
					})
			}
		var pushTimer = setInterval(getAuditPush,1000);

    </script>
</body>
</html>